public class ThreadDemo1 {
    //模拟实现生产消费者模型
    public static void main(String[] args) {
        MyBlockingQueue queue = new MyBlockingQueue();
        //消费者
        Thread t1 = new Thread(() -> {
            while(true){
                try {
                    int value = queue.take();
                    System.out.println("消费："+ value);
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        //生产者
        Thread t2 = new Thread(() ->{
            int value = 0;
            while(true){

                try {
                    System.out.println("生产："+ value);
                    queue.put(value);
                    Thread.sleep(2000);
                    value++;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t1.start();
        t2.start();

    }
}
